import os
import subprocess

PROTO_DIR = "proto"
OUTPUT_DIR = "generated"

if not os.path.exists(OUTPUT_DIR):
    os.makedirs(OUTPUT_DIR)

proto_files = [os.path.join(PROTO_DIR, f) for f in os.listdir(PROTO_DIR) if f.endswith(".proto")]

for proto_file in proto_files:
    command = [
        "python",
        "-m",
        "grpc_tools.protoc",
        f"--proto_path={PROTO_DIR}",
        f"--python_out={OUTPUT_DIR}",
        f"--grpc_python_out={OUTPUT_DIR}",
        proto_file
    ]
    print(' '.join(command))
    subprocess.run(command, check=True)

print("gRPC code generated successfully!")